/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.vfi.bc;
import edu.upn.sigemfi.ope.bc.BovedaFacadeLocal;
import edu.upn.sigemfi.ope.be.Boveda;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
 *
 * @author Alex
 */
public class BovedaDelegate {

        private BovedaFacadeLocal local;

    public BovedaDelegate() {
        local = lookupBovedaFacade();
    }

      public Boveda buscar(Long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupBovedaFacade();
            throw new Exception("Buscar Boveda. " + e.getMessage(), e);
        }
    }
    public List<Boveda> listar() throws Exception {
        try {

            return local.findAll();
        } catch (Exception e) {
            local = lookupBovedaFacade();
            throw new Exception("Listar Bovedas. " + e.getMessage(), e);
        }
    }



    private BovedaFacadeLocal lookupBovedaFacade() {
        try {
            Context c = new InitialContext();
            return (BovedaFacadeLocal) c.lookup("java:comp/env/BovedaFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }




}
